// 函数化构造器的伪代码模板
var constructor = function (spec, my) {
    var that, 其他的私有实例变量;

    my = my || {};

    把共享的变量和函数添加到my中

    that = 一个新对象

    添加给 that 的特权方法

    return that;
};

var mammal = function (spec) {
    var that = {};

    that.get_name = function () {
        return spec.name;
    };

    that.says = function () {
        return spec.saying || '';
    };

    return that;
};

var myMammal = mammal({ name: 'Herb' });

// 在伪类模式里，构造器函数 Cat 不得不重复构造器 Mammal 已经完成的工作。在函数化模式中那不再需要了，因为构造器 Cat 将会调用构造器 Mammal，让 Mammal 去做对象创建中的大部分工作，所以 Cat 只需关注自身的差异既可。
var cat = function (spec) {
    spec.saying = spec.saying || 'meow';
    var that = mammal(spec);
    that.purr = function (n) {
        var i, s = '';
        for (i = 0; i < n;i += 1) {
            if (s) {
                s += '-';
            }
            s += 'r';
        }
        return s;
    };
    that.get_name = function () {
        return this.says + ' ' + this.name + ' ' + this.says;
    };
    return that;
};

var myCat = cat({ name: 'Henrietta' });

Object.method('superior', function (name) {
    var that = this,
        method = that[name];
    return function () {
        return method.apply(that, arguments);
    };
});

var coolcat = function (spec) {
    var that = cat(spec),
        super_get_name = that.superior('get_name');
    that.get_name = function (n) {
        return 'like ' + super_get_name() + ' baby';
    };
    return that;
};

var myCoolCat = coolCat({ name: 'Bix' });
var name = myCoolCat.get_name(); // like mew Bix meow baby